<?php //分页代码
class ShowPage 
{   
    var   $PageSize;         
	var   $Total;                 
	var   $ifram;
	var   $functionname;					              
	//取得总页数   
	function PageCount()   
	{   
		$TotalPage = ($this->Total%$this->PageSize == 0)?floor($this->Total/$this->PageSize):floor($this->Total/$this->PageSize)+1;   
		return   $TotalPage;   
    }   
	
    //取得当前页   
    function   PageNum()  
	 {   
          //if   (isset($_GET['page']))
		  $page = (isset($_GET['page'])!="")?$_GET['page']:$page = 1;     
          return $page; 
	  }   
//查询语句定位指针   
function   OffSet()   {   
         if   ($this->PageNum()>$this->PageCount())   {   
                  $this->PageNum = $this->PageCount();   
                  $pagemin = max(0,$this->Total - $this->PageSize - 1);   
                                                      }
				  elseif ($this->PageNum() == 1){   
                          $pagemin = 0;   
                                                 }
				  else   {   
              $pagemin = min($this->Total - 1,$this->PageSize * ($this->PageNum() - 1));   
                          }   
         return $pagemin.",".$this->PageSize;   
                      }   
//定位首页   
function   FristPage(){
        $href = $this->ifram==1?"javascript:".$this->functionname."('?page=1".$this->Url()."')":"?page=1".$this->Url()."";
        $Frist = ($this->PageNum() <= 1)?"<dt><a href=\"#\">首页</a></dt>":"<dt><a href=\"".$href."\" title=\"首页\">首页</a></dt>"; 
        return $Frist;   
                         }   
//定位上一页   
function   PrePage()   {   
        $prepage=$this->PageNum() - 1;
		$href = $this->ifram==1?"javascript:".$this->functionname."('?page=".$prepage.$this->Url()."')":"?page=".$prepage.$this->Url()."";
        $Previous = ($this->PageNum() >= 2)?"<dt><a href=\"".$href."\" title=\"上一页\">上一页</a></dt>":"<dt><a href=\"#\">上一页</a></dt>";     
            return   $Previous;   
                        }   
//定位下一页
function   NextPage()   {   
        $nextpage = $this->PageNum() + 1;
		$href = $this->ifram==1?"javascript:".$this->functionname."('?page=".$nextpage.$this->Url()."')":"?page=".$nextpage.$this->Url()."";
        $Next = ($this->PageNum() <= $this->PageCount()-1)?"<dt><a href=\"".$href."\" title=\"下一页\">下一页</a></dt>":"<dt><a href=\"#\">下一页</a></dt>";      
          return   $Next;   
                        }   
//定位最后一页   
function   LastPage()   {
		$href = $this->ifram==1?"javascript:".$this->functionname."('?page=".$this->PageCount().$this->Url()."')":"?page=".$this->PageCount().$this->Url().""; 
       $Last = ($this->PageNum() >= $this->PageCount())? " <dt><a href=\"#\">尾页</a></dt >":"<dt><a href=\"".$href."\" title=\"尾页\">尾页</a></dt>";      
  return   $Last;   
                         }   
//下拉跳转页面   
function   JumpPage()   {   
             $tomode=$this->ifram==1?$this->functionname."(this.options[this.selectedIndex].value)":"javascript:location=this.options[this.selectedIndex].value;";
             $Jump = "<dt style='border:0'>第 <select name=page onchange=\"".$tomode."\">";   
                 for($i=1;$i<=$this->PageCount();$i++) {   
                        if   ($i==$this->PageNum())   
                    $Jump.= "<option value=\"?page=".$i.$this->Url()."\" selected>$i</option>";   
                else     
             $Jump.="<option value=\"?page=".$i.$this->Url()."\">$i</option>";   
                                       }   
             $Jump.="</select> 页</dt>";   
               return   $Jump;   
                       }
//URL参数处理   
function  Url()   {      
             $fullurl = $_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING'];
             $allstrict=explode('?',$fullurl);
			 $url = end($allstrict);
			 $url = preg_match("/&page=[\s\S]*&/",$url)?preg_replace("/&page=[^&]*&/","&",$url):preg_replace("/[&]?page=[^&]*[&]?/","",$url);
			 return strpos($fullurl,'?')?"&".$url:"";
                       }  					   

function  SumOver(){
                $zhongshu =$this->PageCount()."页/".$this->Total."条";  
                return $zhongshu;				
}

//记录总数
function  sum(){
                $zhongshu = "<dt>共".$this->PageCount()."页/".$this->Total."条信息&nbsp;</dt>";  
                return $zhongshu;				
}

//生成导航条   
function ShowLink(){
    $pagestr=NULL;
    $i=0;
	$href = $this->ifram==1?"javascript:".$this->functionname."('?page=".$i.$this->Url()."')":"?page=".$i.$this->Url().""; 
	if($this->PageCount()<9 || ($this->PageCount()>=9 && $this->PageNum()<5)){
	     $mm = $this->PageCount()+1;
		 $mmax = $this->PageCount()>=9?10:$mm;
		 for($i=1;$i<$mmax;$i++){
		  $href = $this->ifram==1?"javascript:".$this->functionname."('?page=".$i.$this->Url()."')":"?page=".$i.$this->Url().""; 
		  $pagestr .= $i==$this->PageNum()?"<dt><a class=\"onnum\">".$i."</a></dt>":"<dt><a href=\"".$href."\">".$i."</a></dt>";
		 }
	}else{
	     $min = $this->PageNum()-4;
		 $min_t = $this->PageCount()-8;
		 $max = $this->PageNum()+5;
		 $max_t = $this->PageCount()+1;
		 $min = $max>$this->PageCount()?$min_t:$min;
		 $max = $max>$this->PageCount()?$max_t:$max;	
		 for($i=$min;$i<$max;$i++){
		   $href = $this->ifram==1?"javascript:".$this->functionname."('?page=".$i.$this->Url()."')":"?page=".$i.$this->Url().""; 
		   $pagestr .= $i==$this->PageNum()?"<dt><a href='#' class=\"onnum\">".$i."</a></dt>":"<dt><a href=\"".$href."\">".$i."</a></dt>";
		 }
	}
//	if($this->Total > $this->PageSize){
	$pages = "<dt>".$this->sum().$this->FristPage().$this->PrePage().$pagestr.$this->NextPage().$this->LastPage().$this->JumpPage()."<dt>";
//	}
	return $pages;
}				 
   }    
   ?> 